package com.xiaoyu.izf.model;

import cn.hutool.core.date.DateUtil;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import javax.persistence.*;
import java.sql.Timestamp;
import java.util.Objects;

@Entity
@Table(name = "goods_order", schema = "izf", catalog = "")
public class GoodsOrder {
    private String id;
    private Integer goodsId;
    private String outTradeNo;
    private Integer uid;
    private Integer totalAmount;
    private Integer orderPrice;
    private Integer buyNum;
    private String openId;
    private String channel;
    private Integer orderStatus; //0:下单，1：已支付，-1：申请退款，-2：通过申请退款,-3:申请退款被否，2：已退款，11：已支付并发货，12：完成交易，-11：发货申请退款，-12：交易完成申请退款
    private Timestamp insertTime;
    private Timestamp payTime;
    private Timestamp returnTime;
    private Integer isTest;
    private Integer exWarehouse;
    private Integer sendOut;


    private String insertTimeStr;
    private String payTimeStr;
    private GoodsInfo goodsInfo;
    private UserInfo buyUser;

    @Id
    @Column(name = "id")
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @Basic
    @Column(name = "goods_id")
    public Integer getGoodsId() {
        return goodsId;
    }

    public void setGoodsId(Integer goodsId) {
        this.goodsId = goodsId;
    }

    @Basic
    @Column(name = "out_trade_no")
    public String getOutTradeNo() {
        return outTradeNo;
    }

    public void setOutTradeNo(String outTradeNo) {
        this.outTradeNo = outTradeNo;
    }

    @Basic
    @Column(name = "uid")
    public Integer getUid() {
        return uid;
    }

    public void setUid(Integer uid) {
        this.uid = uid;
    }

    @Basic
    @Column(name = "total_amount")
    public Integer getTotalAmount() {
        return totalAmount;
    }

    public void setTotalAmount(Integer totalAmount) {
        this.totalAmount = totalAmount;
    }

    @Basic
    @Column(name = "order_price")
    public Integer getOrderPrice() {
        return orderPrice;
    }

    public void setOrderPrice(Integer orderPrice) {
        this.orderPrice = orderPrice;
    }

    @Basic
    @Column(name = "buy_num")
    public Integer getBuyNum() {
        return buyNum;
    }

    public void setBuyNum(Integer buyNum) {
        this.buyNum = buyNum;
    }

    @Basic
    @Column(name = "open_id")
    public String getOpenId() {
        return openId;
    }

    public void setOpenId(String openId) {
        this.openId = openId;
    }

    @Basic
    @Column(name = "channel")
    public String getChannel() {
        return channel;
    }

    public void setChannel(String channel) {
        this.channel = channel;
    }

    @Basic
    @Column(name = "order_status")
    public Integer getOrderStatus() {
        return orderStatus;
    }

    public void setOrderStatus(Integer orderStatus) {
        this.orderStatus = orderStatus;
    }

    @Basic
    @Column(name = "insert_time")
    public Timestamp getInsertTime() {
        return insertTime;
    }

    public void setInsertTime(Timestamp insertTime) {
        this.insertTime = insertTime;
    }

    @Basic
    @Column(name = "pay_time")
    public Timestamp getPayTime() {
        return payTime;
    }

    public void setPayTime(Timestamp payTime) {
        this.payTime = payTime;
    }

    @Basic
    @Column(name = "return_time")
    public Timestamp getReturnTime() {
        return returnTime;
    }

    public void setReturnTime(Timestamp returnTime) {
        this.returnTime = returnTime;
    }

    @Basic
    @Column(name = "is_test")
    public Integer getIsTest() {
        return isTest;
    }

    @Basic
    @Column(name = "ex_warehouse")
    public Integer getExWarehouse() {
        return exWarehouse;
    }
    public void setExWarehouse(Integer exWarehouse) {
        this.exWarehouse = exWarehouse;
    }

    @Basic
    @Column(name = "send_out")
    public Integer getSendOut() {
        return sendOut;
    }
    public void setSendOut(Integer sendOut) {
        this.sendOut = sendOut;
    }

    public void setIsTest(Integer isTest) {
        this.isTest = isTest;
    }
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        GoodsOrder that = (GoodsOrder) o;
        return Objects.equals(id, that.id) &&
                Objects.equals(goodsId, that.goodsId) &&
                Objects.equals(outTradeNo, that.outTradeNo) &&
                Objects.equals(uid, that.uid) &&
                Objects.equals(totalAmount, that.totalAmount) &&
                Objects.equals(orderPrice, that.orderPrice) &&
                Objects.equals(buyNum, that.buyNum) &&
                Objects.equals(openId, that.openId) &&
                Objects.equals(channel, that.channel) &&
                Objects.equals(orderStatus, that.orderStatus) &&
                Objects.equals(insertTime, that.insertTime) &&
                Objects.equals(payTime, that.payTime) &&
                Objects.equals(returnTime, that.returnTime);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, goodsId, outTradeNo, uid, totalAmount, orderPrice, buyNum, openId, channel, orderStatus, insertTime, payTime, returnTime);
    }

    @Transient
    public String getInsertTimeStr() {
        return DateUtil.formatDateTime(insertTime);
    }

    @Transient
    public String getPayTimeStr() {
        return DateUtil.formatDateTime(payTime);
    }

    @ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.LAZY, optional = true)
    @NotFound(action = NotFoundAction.IGNORE)
    @JoinColumn(name = "goods_id", referencedColumnName = "id", insertable = false, updatable = false)
    public GoodsInfo getGoodsInfo() {
        return goodsInfo;
    }

    public void setGoodsInfo(GoodsInfo goodsInfo) {
        this.goodsInfo = goodsInfo;
    }


    @ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.LAZY, optional = true)
    @NotFound(action = NotFoundAction.IGNORE)
    @JoinColumn(name = "uid", referencedColumnName = "id", insertable = false, updatable = false)
    public UserInfo getBuyUser() {
        return buyUser;
    }

    public void setBuyUser(UserInfo buyUser) {
        this.buyUser = buyUser;
    }
}
